﻿package mortal.game.scene3D.map3D.util
{
    import Message.Public.*;
    import com.fyGame.fyMap.*;
    import com.gengine.game.*;
    import com.gengine.resource.info.*;
    import flash.geom.*;
    import mortal.common.global.*;
    import mortal.game.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.map3D.sceneInfo.*;

    public class MapFileUtil extends Object
    {
        public static var mapInfo:GMapInfo;
        private static var _mapID:int;
        private static var _mapScene:int = -1;
        private static var _proxyID:int;
        private static var _serverID:int;
        private static var _currentMapPath:String;
        private static var _mapDataPath:String;
        private static var _sceneDataPath:String;
        private static const CONNECT:String = "_";
        private static const PNG:String = ".png";
        private static const JPG:String = ".jpg";
        private static const BG:String = "bg";
        private static const ABC:String = ".abc";
        private static const CMP0:String = ".cmp0";
        private static const CMP1:String = ".cmp1";

        public function MapFileUtil()
        {
            return;
        }// end function

        public static function get mapID() : int
        {
            return _mapID;
        }// end function

        public static function get sceneDataPath() : String
        {
            return _sceneDataPath;
        }// end function

        public static function get mapDataPath() : String
        {
            return _mapDataPath;
        }// end function

        public static function set mapID(param1:int) : void
        {
            var _loc_2:ResourceInfo = null;
            if (param1 == _mapID)
            {
                return;
            }
            if (_mapScene != -1)
            {
                _loc_2 = SceneConfig.instance.getImageInfo(_mapScene);
                if (_loc_2 && _loc_2.isLoaded)
                {
                    _loc_2.dispose();
                }
            }
            _mapID = param1;
            _currentMapPath = MapConfig.mapPath + "" + _mapID;
            mapInfo = GameMapConfig.instance.getMapInfo(_mapID);
            _mapDataPath = getMapDataPathByMapId(_mapID);
            _mapScene = mapInfo.mapscene;
            MapVague.instance.dispose();
            MapVague.instance.loadMinMap();
            return;
        }// end function

        public static function get mapScene() : int
        {
            return _mapScene;
        }// end function

        public static function set proxyID(param1:int) : void
        {
            _proxyID = param1;
            return;
        }// end function

        public static function get proxyID() : int
        {
            return _proxyID;
        }// end function

        public static function set serverID(param1:int) : void
        {
            _serverID = param1;
            return;
        }// end function

        public static function get serverID() : int
        {
            return _serverID;
        }// end function

        public static function getPiecePath(param1:int, param2:int) : String
        {
            var _loc_3:Boolean = false;
            if (ParamsConst.instance.isUseATF)
            {
                _loc_3 = Game.mapInfo.getPicType(param1, param2) == MapPicType.JPG;
                if (_loc_3)
                {
                    return _mapScene + CONNECT + param2 + CONNECT + param1 + CMP0;
                }
                return _mapScene + CONNECT + param2 + CONNECT + param1 + CMP1;
            }
            else
            {
                return _mapScene + CONNECT + param2 + CONNECT + param1 + ABC;
            }
        }// end function

        public static function getPieceFarPath(param1:int, param2:int) : String
        {
            if (ParamsConst.instance.isUseATF)
            {
                return _mapID + CONNECT + param2 + CONNECT + param1 + CONNECT + BG + CMP0;
            }
            return _mapID + CONNECT + param2 + CONNECT + param1 + CONNECT + BG + ABC;
        }// end function

        public static function getJtaPath(param1:Object) : String
        {
            return param1 + "_fr.jta";
        }// end function

        public static function getMapDataPathByMapId(param1:int) : String
        {
            return ResConfig.instance.getUrlByName(param1 + "_map.mpt");
        }// end function

        public static function getModelPath(param1:Object) : String
        {
            return param1 + "";
        }// end function

        public static function getMiniMapPath() : String
        {
            return _mapID + "_mini.jpg";
        }// end function

        public static function getMiniMapPathByMap(param1:int) : String
        {
            return param1 + "_mini.jpg";
        }// end function

        public static function isTopPicBlank(param1:int, param2:int) : Boolean
        {
            return Game.mapInfo.getPicType(param1, param2) == MapPicType.BLANK;
        }// end function

        public static function get isInCrossAutofightMap() : Boolean
        {
            if (mapID == 90001)
            {
                return true;
            }
            if (mapID == 90010)
            {
                return true;
            }
            if (mapID == 90012)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInCrossNormalMap() : Boolean
        {
            var _loc_2:int = 0;
            var _loc_1:* = SceneConfig.instance.getSceneInfo(mapID);
            if (_loc_1)
            {
                _loc_2 = _loc_1.sMapDefine.instanceType.__value;
                return _loc_2 == EMapInstanceType._EMapInstanceTypeCrossNormal;
            }
            return false;
        }// end function

        public static function get isInLocalShowAutofightWinMap() : Boolean
        {
            return mapID == 10004 || mapID == 90000 || mapID == 90011 || mapID == 10005 || mapID == 10006;
        }// end function

        public static function isBgNotNeedDraw(param1:int, param2:int) : Boolean
        {
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_3:* = param1 * MapConst.pieceWidth - SceneRange.bitmapFarXY.left;
            var _loc_4:* = param2 * MapConst.pieceHeight - SceneRange.bitmapFarXY.top;
            _loc_5 = int((_loc_3 + SceneRange.display.left) / MapConst.pieceWidth);
            _loc_6 = int((_loc_4 + SceneRange.display.top) / MapConst.pieceHeight);
            var _loc_7:* = new Rectangle(_loc_5 * MapConst.pieceWidth, _loc_6 * MapConst.pieceHeight, MapConst.pieceWidth, MapConst.pieceHeight);
            if (!SceneRange.display.intersection(_loc_7).isEmpty() && Game.mapInfo.getPicType(_loc_5, _loc_6) != MapPicType.JPG)
            {
                return false;
            }
            _loc_5 = int((_loc_3 + SceneRange.display.left + MapConst.pieceWidth - 1) / MapConst.pieceWidth);
            _loc_6 = int((_loc_4 + SceneRange.display.top) / MapConst.pieceHeight);
            _loc_7 = new Rectangle(_loc_5 * MapConst.pieceWidth, _loc_6 * MapConst.pieceHeight, MapConst.pieceWidth, MapConst.pieceHeight);
            if (!SceneRange.display.intersection(_loc_7).isEmpty() && Game.mapInfo.getPicType(_loc_5, _loc_6) != MapPicType.JPG)
            {
                return false;
            }
            _loc_5 = int((_loc_3 + SceneRange.display.left) / MapConst.pieceWidth);
            _loc_6 = int((_loc_4 + SceneRange.display.top + MapConst.pieceHeight - 1) / MapConst.pieceHeight);
            _loc_7 = new Rectangle(_loc_5 * MapConst.pieceWidth, _loc_6 * MapConst.pieceHeight, MapConst.pieceWidth, MapConst.pieceHeight);
            if (!SceneRange.display.intersection(_loc_7).isEmpty() && Game.mapInfo.getPicType(_loc_5, _loc_6) != MapPicType.JPG)
            {
                return false;
            }
            _loc_5 = int((_loc_3 + SceneRange.display.left + MapConst.pieceWidth - 1) / MapConst.pieceWidth);
            _loc_6 = int((_loc_4 + SceneRange.display.top + MapConst.pieceHeight - 1) / MapConst.pieceHeight);
            _loc_7 = new Rectangle(_loc_5 * MapConst.pieceWidth, _loc_6 * MapConst.pieceHeight, MapConst.pieceWidth, MapConst.pieceHeight);
            if (!SceneRange.display.intersection(_loc_7).isEmpty() && Game.mapInfo.getPicType(_loc_5, _loc_6) != MapPicType.JPG)
            {
                return false;
            }
            return true;
        }// end function

    }
}
